SITE GUARD  v1.0
Falcon Gaming Studios, LLC  -  https://falcongamingstudios.com

Watches your website's files. If a file is changed, deleted or added without your
approval, Site Guard emails you and puts the approved copy back automatically.
It also checks that your homepage is up and still shows the text you expect.

Works on any Linux web host with PHP 8.0+ and cron jobs, including shared hosting
with no SSH/terminal (cPanel, Plesk, DirectAdmin and similar). Best suited to static
sites and sites that don't change files on their own (see LIMITS).

-------------------------------------------------------------------------------
FILES
  guard.php            The program.
  config.example.php   Settings template. Copy to config.php and fill it in.
  .htaccess            Blocks web access to the folder (Apache/LiteSpeed).
  README.txt           This file.
  Site-Guard-Manual.pdf  Full manual with step-by-step setup.

-------------------------------------------------------------------------------
SETUP (about 10 minutes)

1. Upload the "Site Guard" folder to your hosting account, OUTSIDE the web root.
   Good:  /home/USERNAME/site-guard/
   Bad:   /home/USERNAME/public_html/site-guard/
   (Site Guard refuses to run from inside the folder it watches.)

2. Copy config.example.php to config.php and fill in:
     alert_to      your email (preferably not hosted on the same server)
     docroot       the folder your site is served from
     url           your homepage
     must_contain  text only your real homepage contains (e.g. your company name)
   Add more entries under 'sites' to watch several sites from one install.

3. Create a cron job (hosting panel > Cron Jobs), every 10 minutes:

   */10 * * * * /usr/local/bin/php -q /home/USERNAME/site-guard/guard.php check --quiet >> /home/USERNAME/site-guard/data/cron.log 2>&1

   Replace USERNAME with your account name. If /usr/local/bin/php doesn't exist on
   your host, ask your host for the PHP CLI path (often /usr/bin/php).

4. Wait for the first run. You'll get a "Now protecting" email: the current files
   are saved as the approved copy. No email within 15 minutes? See TROUBLESHOOTING.

-------------------------------------------------------------------------------
UPDATING YOUR SITE  (do this every time, or Site Guard undoes your changes)

1. In the site-guard folder, create an empty file named   pause-<key>
   (<key> is the site's name in config.php, e.g. pause-mysite)
2. Upload your changes.
3. Rename the file to   approve-<key>
   On its next run Site Guard saves the live files as the new approved copy,
   deletes the control file and emails you a confirmation.

If you forget step 3, you'll get a reminder email after 12 hours.

-------------------------------------------------------------------------------
ALERT EMAILS
  Now protecting     First run finished; approved copy saved.
  RESTORED           Unapproved changes were found and fully undone.
  ACTION NEEDED      Something couldn't be fixed automatically (homepage down,
                     text missing, a file that has no backup copy, a failed restore).
  Approved           Your approve- file was processed; new approved copy saved.
  REMINDER           A site has been paused for more than 12 hours.

The same unresolved problem is emailed once, not every 10 minutes.

-------------------------------------------------------------------------------
COMMANDS (if you have SSH; otherwise cron does everything)
  php guard.php check [site] [--full]   Compare files with the approved copy.
  php guard.php baseline <site|all>     Save the live files as the approved copy.
  php guard.php status                  Show each site's approved copy info.
  php guard.php test-email              Send a test alert.

-------------------------------------------------------------------------------
SETTINGS (per site, in config.php)
  restore         true = put changed/deleted files back.  false = alert only.
  quarantine_new  true = move unknown new files to data/<key>/quarantine/.
                  false = alert only.
  ignore          File patterns never watched. Add folders your site writes to
                  itself (uploads/*, cache/*), or every upload looks like an attack.
  no_copy         File patterns watched but not backed up (huge videos). Changes
                  are reported but can't be restored.

-------------------------------------------------------------------------------
LIMITS
  - Not for sites that change their own files (WordPress uploads, plugin updates,
    caches) unless you list those folders in 'ignore'.
  - The approved copy uses as much disk space as your site (minus 'no_copy' files).
  - Site Guard detects and repairs file changes. It does not replace backups,
    a firewall or keeping your passwords and software up to date.
  - Email is sent with PHP mail(). Some hosts block it or send it to spam; send a
    test with  php guard.php test-email  or check data/guard.log.

-------------------------------------------------------------------------------
TROUBLESHOOTING
  No email at all        Check data/cron.log and data/guard.log. "EMAIL FAILED"
                         means the host blocked mail(); set alert_from to an
                         address on your own domain, or ask your host.
  data/ folder is empty  The cron job isn't running: check the PHP path and the
                         folder path in the cron command.
  "config.php problems"  The log lists what to fix in config.php.
  "SETUP PROBLEM" email  'docroot' points to an empty or wrong folder.
  My upload was undone   You uploaded without pause-<key>. Upload again using the
                         UPDATING steps.
  Alerts about files     Add those files or folders to 'ignore'.
  my site writes itself

-------------------------------------------------------------------------------
LICENSE
Copyright © 2026 - Falcon Gaming Studios, LLC - All Rights Reserved.
This file is free and open source.
It may be used, copied, and redistributed in any form (modified or unmodified), in any project or future works, personal or commercial.
Unmodified copies must keep this copyright notice and permission notice intact.
Modified copies require that the copyright notice above, including this permission notice, be removed or replaced.
THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM ITS USE.

